﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Domain.Repositories;
using YAPACS.BusinessObjects.Managements.Exams;
using YAPACS.Organizations;

namespace YAPACS.RisServer.Controllers;
[Authorize]
public class ExamMethodController : AbpControllerBase
{
    private readonly IRepository<ExamMethod, Guid> _examMethodRepository;
    private readonly ICurrentUserOrganization _currentUserOrganization;

    public ExamMethodController(IRepository<ExamMethod, Guid> examMethodRepository, ICurrentUserOrganization currentUserOrganization)
    {
        _examMethodRepository = examMethodRepository;
        _currentUserOrganization = currentUserOrganization;
    }

    [HttpGet("api/get-exam-methods-options/{deviceType}")]
    public async Task<IActionResult> GetExamMethodsByDeviceTypeAsync(Guid deviceType, [FromQuery] int sex)
    {
        List<ExamMethod> list = await _examMethodRepository.GetListAsync(e => e.DeviceType.Oid == deviceType && e.Department.Oid == _currentUserOrganization.DepartmentId);
        var result = list.Select(e => new
        {
            Label = e.Name,
            Value = e.Oid
        });
        return Ok(result);
    }
}
